package com.polaris.live.adapter

import com.blankj.utilcode.util.StringUtils
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.util.DateUtils
import com.polaris.live.databinding.ItemGiftRecordBinding
import com.polaris.live.resp.back_resp.BackpackReceivesResp
import com.polaris.live.translation.R.*

/**
 * 获赠记录item
 *
 * @author Created by 天晴 on 2024/7/17/015 17:13
 */
class GiftRecordAdapter : BaseBindingAdapter<ItemGiftRecordBinding, BackpackReceivesResp>() {
    init {
        addChildClickViewIds(R.id.user_ll, R.id.time_ll)
    }

    override fun convert(
        holder: VBViewHolder<ItemGiftRecordBinding>,
        item: BackpackReceivesResp,
    ) {
        holder.vb.apply {
            name.text = item.userBasic.nickname
            time.text = item.createTime.let {
                DateUtils.convertTimestampToString(it)
            }
            if (item.duration == -1L) {
                timeLong.text = StringUtils.getString(string.permanent)
            } else {
                val (day, num) = if (item.duration < 365) {
                    "day" to item.duration
                } else {
                    "year" to item.duration / 365
                }
                timeLong.text = "$num$day"
            }
            when (item.getType()) {
                1 -> {
                    timeImg.setImageResource(R.drawable.giftrecord_3)
                }

                2 -> {
                    timeImg.setImageResource(R.drawable.giftrecord_2)
                }

                3 -> {
                    timeImg.setImageResource(R.drawable.giftrecord_1)
                }
            }
        }
    }

}

